import { getUserSheetAPI } from "@/api/index";

export default {
    namespaced:true,
    actions:{
        // 获取用户歌单
        async getUserSheet(context,value){
            const res = await getUserSheetAPI({uid:context.state.userID});
            let arr = res.data.playlist;
            let user = [];
            let star = [];
            arr.forEach(element => {
                if(element.userId==context.state.userID){
                    user.push(element);
                }else{
                    star.push(element);
                }
            });
            user[0].name='我喜欢的音乐';
            context.commit('updateUserSheet',user);
            context.commit('updateUserStarSheet',star);
        },
        clearInfo(context,value){
            context.commit('updateUserID',0);
            context.commit('updateNickName',null);
            context.commit('updateUserImg',null);
            context.commit('updateToken',null);
            context.commit('updateUserSheet',[]);
            context.commit('updateUserStarSheet',[]);
        }
    },
    mutations:{
        updateUserID(state,value){
            state.userID = value;
        },
        updateNickName(state,value){
            state.nickName = value;
        },
        updateUserImg(state,value){
            state.userImg = value;
        },
        updateToken(state,value){
            state.token = value
        },
        updateUserSheet(state,value){
            state.userSheet = value
        },
        updateUserStarSheet(state,value){
            state.userStarSheet = value
        }
    },
    state:{
        userID:0,
        nickName:null,
        userImg:null,
        token:null,
        userSheet:[],
        userStarSheet:[]
    }
}